/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Button, TextArea, Text, useToast,} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl} from "../../common/base";
import {useMedia} from "use-media";
import {assertNamesUnique} from "../../common/eHelper";
import {itemA下结论} from "./editor";
import {itemA查材料, } from "./editorReview";
import {EditStorageContext} from "../../StorageContext";
import {itemA发证} from "./editorCert";
import {configSetter} from "./Regular.O-1";
import {Each_ZdSetting, useTableEditor} from "../../hook/useRepTableEditor";
import {useMeasureInpFilter} from "../../common/hooks";
import {itemA宏观焊接} from "./editorMacr";
import {itemA附件紧急} from "./editorAcces";

export const config设备概况 = [
    [['使用单位', '_$使用单位'], ],
    [['联系地址', '_$使用单位地址'],  ],
    [['联系人员', '安全员'], ['联系电话', '安全员电'] ],
    [['VIN', '_$车架号'],  ],
    [['罐体代码', '_$设计代码'], ['盛装介质', '_$盛装介质'] ],
    [['检验地址', '检验地址'],  ],
];

export const EntranceSetup =
    React.forwardRef((
        {children, show, alone = true, repId, verId, rep}: InternalItemProps, ref
    ) => {
        const atPrint = useMedia('print');
        const toast = useToast();
        const doCheckNames = React.useCallback((verId: string) => {
            //【承压更少项目】，那些属于公共模板目录的 分项报告的唯一性检查在对方自己检查看。
            const result = assertNamesUnique([{value: rep?.tzFields},
                {value: configSetter(verId,), type:'esnt'},
                //{value: config证书概要, type:'esnt'},
                {value:[...itemA下结论, ...itemA查材料, ...itemA宏观焊接, ...itemA附件紧急, ...itemA发证 ]},
                {value:['Projects', '适装表', ]} ]);
            toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
        }, [rep,toast]);
        const {storage, setStorage} =React.useContext(EditStorageContext) as any;
        const getInpFilter = React.useCallback((par: any) => {
            const {_tblFixed, } =par||{};
            return {_tblFixed, };
        }, []);
        const {inp, setInp} = useItemInputControl({ref});
        if (atPrint) return null;
        else return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={'初始化本报告，默认值配置等'}>
                {process.env.REACT_APP_TEST==='true' && <><div>
                    <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
                    <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
                    <Text variant="h5">设置待测试表格的各列宽度：</Text>
                    <TextArea value={storage?._tblFixed || ''} rows={2}
                            onChange={e => setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}) }/>
                    </div>
                </>
                }
                <hr/>
            </InspectRecordLayout>
        );
    });


export const config适装=[['UN＋介质名称','n',330], ] as Each_ZdSetting[];
const itemA适装=['适装表', ];
export const AdaptingMedium=
    React.forwardRef(({ children, show ,alone=true,refWidth,redId,nestMd,label}:InternalItemProps,  ref
    ) => {
        const [getInpFilter]=useMeasureInpFilter(null,itemA适装, );
        const {inp, setInp} = useItemInputControl({ ref,redId,nestMd });
        const headview=<Text variant="h5">
            {label}。
        </Text>;
        const [render部位汇总]=useTableEditor({inp, setInp,  headview,
            config: config适装, table: '适装表', column:2,  maxRf:4, });

        return (
            <InspectRecordLayout inp={inp} setInp={setInp}  getInpFilter={getInpFilter} show={show}  redId={redId} nestMd={nestMd}
                                 alone={alone}  label={label!}>
                {render部位汇总}
            </InspectRecordLayout>
        );
    } );

